package com.deer.wms.system.manage.service.impl;

import com.deer.wms.project.root.service.SuperServiceImpl;
import com.deer.wms.system.manage.dao.UserOrganizationMapper;
import com.deer.wms.system.manage.model.organization.Organization;
import com.deer.wms.system.manage.model.organization.UserOrganization;
import com.deer.wms.system.manage.model.organization.UserOrganizationCriteria;
import com.deer.wms.system.manage.model.organization.UserOrganizationDto;
import com.deer.wms.system.manage.service.OrganizationService;
import com.deer.wms.system.manage.service.UserOrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by guo on 2019/11/05.
 */
@Service
@Transactional
public class UserOrganizationServiceImpl extends SuperServiceImpl<UserOrganizationMapper, UserOrganization> implements UserOrganizationService {

    @Autowired
    private UserOrganizationMapper userOrganizationMapper;

    @Autowired
    private OrganizationService organizationService;



    @Override
    public List<UserOrganizationDto> findList(UserOrganizationCriteria criteria) {
        return userOrganizationMapper.findList(criteria);
    }

    @Override
    public void addUserOrganization(Integer userId, Integer organizationId) {
            UserOrganization userOrganization = new UserOrganization();
            userOrganization.setUserId(userId);
            userOrganization.setOrganizationId(organizationId);
            super.save(userOrganization);
            Organization organization = organizationService.getById(organizationId);
            organization.setOrganizationStatus("enable");
            organizationService.updateById(organization);
    }

    @Override
    public void deleteByUserId(Integer userId) {
        userOrganizationMapper.deleteByUserId(userId);
    }

    @Override
    public void deleteByOrganizationId(Integer organizationId) {
        userOrganizationMapper.deleteByOrganizationId(organizationId);
    }


}
